package com.atguigu.distributed.lock.leecode;

import java.util.Scanner;

/**
 * 详细题目见下方链接，该题为华为OD机试题目：停车场需要打开多少个监控器
 * https://blog.csdn.net/qfc_128220/article/details/130632804
 */
public class ParkMonitor {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        int n = scanner.nextInt();
        int[][] matrix = new int[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                matrix[i][j] = scanner.nextInt();
            }
        }
        System.out.println(getResult(m, n, matrix));
    }

    public static int getResult(int m, int n, int[][] matrix) {
        int count = 0;
        int[][] offsets = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
        for (int x = 0; x < m; x++) {
            for (int y = 0; y < n; y++) {
                if (matrix[x][y] == 1) {
                    count++;
                    continue;
                }
                for (int[] offset : offsets) {
                    int newX = x + offset[0];
                    int newY = y + offset[1];
                    if (newX >= 0 && newX < m && newY >= 0 && newY < n && matrix[newX][newY] == 1) {
                        count++;
                        break;
                    }
                }
            }

        }
        return count;
    }
    //下列为原代码出处
//    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
//
//        int m = sc.nextInt();
//        int n = sc.nextInt();
//
//        int[][] matrix = new int[m][n];
//        for (int i = 0; i < m; i++) {
//            for (int j = 0; j < n; j++) {
//                matrix[i][j] = sc.nextInt();
//            }
//        }
//
//        System.out.println(getResult(m, n, matrix));
//    }
//
//    public static int getResult(int m, int n, int[][] matrix) {
//        int count = 0;
//        int[][] offsets = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
//
//        for (int x = 0; x < m; x++) {
//            for (int y = 0; y < n; y++) {
//                if (matrix[x][y] == 1) {
//                    count++;
//                    continue;
//                }
//
//                for (int[] offset : offsets) {
//                    int newX = x + offset[0];
//                    int newY = y + offset[1];
//
//                    if (newX >= 0 && newX < m && newY >= 0 && newY < n && matrix[newX][newY] == 1) {
//                        count++;
//                        break;
//                    }
//                }
//            }
//        }
//
//        return count;
//    }
}
